package org.example.struct.array;

import java.util.HashSet;
import java.util.Set;

/**
 * @author liyishan
 * @date 2024/7/16 09:51
 * @apiNote
 */

public class Test02956FindIntersectionValues {

    public int[] findIntersectionValues(int[] nums1, int[] nums2) {
        int n = nums1.length, m = nums2.length;
        int[] res = new int[]{0, 0};
        Set<Integer> set1 = new HashSet<>();
        Set<Integer> set2 = new HashSet<>();

        for (int i = 0; i < n; i++) {
            set1.add(nums1[i]);
        }
        for (int i = 0; i < m; i++) {
            set2.add(nums2[i]);
        }
        for(int i = n-1; i >= 0; i--) {
            if (set2.contains(nums1[i])) {
                res[0]++;
            }
        }
        for (int i = m-1; i >= 0; i--) {
            if (set1.contains(nums2[i])) {
                res[1]++;
            }
        }
        return res;
    }
}
